/* eth2ap (Ethernet to Wi-Fi AP packet forwarding) Example

   This example code is in the Public Domain (or CC0 licensed, at your option.)

   Unless required by applicable law or agreed to in writing, this
   software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
   CONDITIONS OF ANY KIND, either express or implied.
*/
#include <string.h>
#include <stdlib.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
#include "esp_event.h"
#include "esp_log.h"
#include "esp_eth.h"
#include "esp_wifi.h"
#include "nvs_flash.h"
#include "esp_private/wifi.h"
#include "driver/gpio.h"
#include "sdkconfig.h"
// #include "my_http_server.h"
#include "esp_idf_version.h"
#include "my_dev_init.h"
#include "my_dev_config.h"

static const char *TAG = "eth_example";


static void show_fw_version(void)
{
    printf("========================================================================================\r\n");   
    printf("     _    ___ _____ _   _ ___ _   _ _  _______ ____        ______        __\r\n");
    printf("    / \\  |_ _|_   _| | | |_ _| \\ | | |/ / ____|  _ \\      / ___\\ \\      / /\r\n");
    printf("   / _ \\  | |  | | | |_| || ||  \\| | ' /|  _| | |_) |____| |  _ \\ \\ /\\ / /\r\n"); 
    printf("  / ___ \\ | |  | | |  _  || || |\\  | . \\| |___|  _ <_____| |_| | \\ V  V /\r\n");  
    printf(" /_/   \\_\\___| |_| |_| |_|___|_| \\_|_|\\_\\_____|_| \\_\\     \\____|  \\_/\\_/\r\n"); 

    printf("\r\nIDF version = %s\n", esp_get_idf_version()); 
    printf("Date: %s %s\n", __DATE__, __TIME__);
    printf("FW version = %s\n",FW_VERSION);  
    printf("========================================================================================\r\n");                                                                
}


static void free_memory(void* parm)
{
    while(1){
        ESP_LOGI(TAG, "[APP] Free memory: %d bytes", esp_get_free_heap_size());
        vTaskDelay(5000/ portTICK_PERIOD_MS);
    }
}


void app_main(void)
{
    esp_err_t ret = nvs_flash_init();
    if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
        ESP_ERROR_CHECK(nvs_flash_erase());
        ret = nvs_flash_init();
    }
    ESP_ERROR_CHECK(ret);

    xTaskCreate(free_memory,"free_memory", 4096, NULL, 5, NULL);
    
    show_fw_version();
    dev_init();
}


